/**
 * Copyright (c) 2010 BullionXpress.com
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */
package com.bullionxpress.shared.util;

import java.util.logging.Level;
import java.util.logging.Logger;
import com.bullionxpress.client.application.ClientGlobals;
import com.bullionxpress.client.view.Console;

/**
 * This class is a wrapper class for logging.
 *
 * @author BullionXpress.com
 * @version 1.4
 */
public class Log {

    /**
     * Suppress the default public constructor to prevent instances of this class.
     */
    private Log() {
    }
    private static boolean debug = true;

    /**
     * This method will allow the logger to be run in debug mode (output)
     * or in regular mode (no output).
     * You can specify the level, with Level
     *
     * @see java.util.logging.Level
     *
     * @param text the text to be logged
     * @param level the log level
     */
    public static void info(String text, Level level) {
        if (isDebug()) {
            Logger.getAnonymousLogger().info(text);
        }
        try {
            try {
                Console console = (Console) ClientGlobals.registry.get("Console");
                if (console != null) {
                    console.println(text);
                }
            } catch(Exception ex){

            }
        } catch(Error err){

        }
    }

    /**
     * Log the text to the logger.
     * @param text the text to be logged
     */
    public static void info(Exception ex) {
        ex.printStackTrace();
        info(ex.toString(), Level.ALL);
    }
    /**
     * Log the text to the logger.
     * @param text the text to be logged
     */
    public static void info(String text) {
        info(text, Level.ALL);
    }

    /**
     * @param debug a boolean value, true to set debug mode on, to turn debug off use false.
     */
    public static void setDebug(boolean debug) {
        Log.debug = debug;
    }

    /**
     * @return true if debug mode set to true, false if not.
     */
    public static boolean isDebug() {
        return debug;
    }
}
